package com.ruoyi.web.controller.ring;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.ring.domain.RingGroup;
import com.ruoyi.ring.service.IRingGroupService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 群组Controller
 * 
 * @author liuwp
 * @date 2025-10-20
 */
@RestController
@RequestMapping("/ring/ring_group")
public class RingGroupController extends BaseController
{
    @Resource
    private IRingGroupService ringGroupService;

    /**
     * 查询群组列表
     */
    @PreAuthorize("@ss.hasPermi('ring:ring_group:list')")
    @GetMapping("/list")
    public TableDataInfo list(RingGroup ringGroup)
    {
        startPage();
        List<RingGroup> list = ringGroupService.selectRingGroupList(ringGroup);
        return getDataTable(list);
    }

    /**
     * 导出群组列表
     */
    @PreAuthorize("@ss.hasPermi('ring:ring_group:export')")
    @Log(title = "群组", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RingGroup ringGroup)
    {
        List<RingGroup> list = ringGroupService.selectRingGroupList(ringGroup);
        ExcelUtil<RingGroup> util = new ExcelUtil<RingGroup>(RingGroup.class);
        util.exportExcel(response, list, "群组数据");
    }

    /**
     * 获取群组详细信息
     */
    @PreAuthorize("@ss.hasPermi('ring:ring_group:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(ringGroupService.selectRingGroupById(id));
    }

    /**
     * 新增群组
     */
    @PreAuthorize("@ss.hasPermi('ring:ring_group:add')")
    @Log(title = "群组", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RingGroup ringGroup)
    {
        return toAjax(ringGroupService.insertRingGroup(ringGroup));
    }

    /**
     * 修改群组
     */
    @PreAuthorize("@ss.hasPermi('ring:ring_group:edit')")
    @Log(title = "群组", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RingGroup ringGroup)
    {
        return toAjax(ringGroupService.updateRingGroup(ringGroup));
    }

    /**
     * 删除群组
     */
    @PreAuthorize("@ss.hasPermi('ring:ring_group:remove')")
    @Log(title = "群组", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(ringGroupService.deleteRingGroupByIds(ids));
    }
}
